package com.itcast.ssm.controller;


import com.itcast.ssm.common.CommonResult;
import com.itcast.ssm.common.CommonResultCode;
import com.itcast.ssm.pojo.Evaluation;
import com.itcast.ssm.response.OwnerEvaluation;
import com.itcast.ssm.service.EvaluationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 房屋评价 前端控制器
 * </p>
 *
 * @author 三人行
 * @since 2020-09-12
 */
@RestController
@RequestMapping("/evaluation")
public class EvaluationController {

    @Autowired
    EvaluationService evaluationService;

    @GetMapping(value = "findAll")
    public CommonResult findAll(@RequestParam(value = "owner_id") Integer ownerId) {
        List<OwnerEvaluation> ownerEvaluations = evaluationService.findAll(ownerId);
        return new CommonResult(CommonResultCode.CommonSuccess, ownerEvaluations);
    }

    @DeleteMapping(value = "")
    public CommonResult delete(@RequestParam(value = "evaluate_id") Integer evaluateId) {
        Integer result = evaluationService.delete(evaluateId);
        if(result <= 0) {
            return CommonResult.CommonFail();
        }
        return CommonResult.CommonSuccess();
    }
}

